
<template>
  <div class="login-container">
    <van-nav-bar title="学生登录"/>
    <div class="login-pic"  align="center">
      <img class="login-img" src="../../public/images/Neusoft_login.png">
    </div>
    <van-form @submit="onSubmit" style="margin-top: 18px">
      <van-cell-group inset>

        <van-field
          v-model="username"
          name="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />

        <van-field
          v-model="password"
          type="password"
          name="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </van-cell-group>
      <div class="button1" style="margin: 16px;">
        <van-button round block type="primary" native-type="submit"> 登录</van-button>
      </div>
      <div style="margin: 16px">
        <van-button round block to="/signup"> 还没有账号？去注册！</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {showFailToast, showLoadingToast, showSuccessToast} from "vant";

export default {
  name: "LibraryAppLoginView",

  data() {
    return {
      username: "",
      password: "",
      uuid: "",
    };
  },

  methods: {
    onSubmit() {
      showLoadingToast({
        message: "登录中...",
        forbidClick: true,
        duration: 0,
      });
      this.axios
        .post("/login", {
          username: this.username,
          password: this.password,
        })
        .then((res) => {
          if (res.data && res.data.code == 200) {
            sessionStorage.token = res.data.token;
            showSuccessToast("登录成功");
            this.$router.push({ name: 'home' })
          } else {
            showFailToast("登录失败");
          }
        })
        .catch((err) => {
          console.log(err);
          showFailToast("登录失败");
        });
    },
  },
};
</script>

<style scoped lang="less">

.login-container {
  background-color: #fff;
  min-height: calc(100vh - 1.22667rem);

  .van-nav-bar {
    font-size: 24px;
    /deep/ .van-nav-bar__title{
      color: #294356;
    }
  }

  img{
    width: 80%;
  }
}
</style>
